package com.springboot.shanhexin.dao;

import com.springboot.shanhexin.entity.my_hotel;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;

import java.util.List;

@Component(value = "my_hotelDao")
public interface my_hotelDao {

    //我的旅店：my_hotel

    /**
     * 显示总数量
     * @return
     */
    @Select("select count(*) from my_hotel")
    int getCount();

    /**
     * 全部分页显示
     * @return
     */
    @Select("select a.title as title,b.name as username,c.* from tourist_route a," +
            "userinfo b,my_hotel c where a.uid=b.openid and c.tid=a.id limit #{pos},#{size}")
    List<my_hotel> findByPage(@Param("pos")int pos, @Param("size")int size);

    /**
     * 显示搜索的总数量
     * @return
     */
    @Select("select a.title as title,b.name as username,c.* from tourist_route a," +
            "userinfo b,my_hotel c where a.uid=b.openid and c.tid=a.id and ${key} like " +
            "concat(concat('%',#{name}),'%')")
    int getsearchCount(@Param("key")String key,@Param("name")String name);

    /**
     * 搜索并分页显示
     * @return
     */
    @Select("select a.title as title,b.name as username,c.* from tourist_route a," +
            "userinfo b,my_hotel c where a.uid=b.openid and c.tid=a.id and ${key} like " +
            "concat(concat('%',#{name}),'%') limit #{pos},#{size}")
    List<my_hotel> findsearchByPage(@Param("key")String key, @Param("name")String name, @Param("pos")int pos, @Param("size")int size);

    /**
     * 新增
     */
    @Insert("insert into my_hotel(tid,name) values(#{tid},#{name})")
    void add(my_hotel my_hotel);

    /**
     * 删除
     */
    @Delete("DELETE FROM my_hotel WHERE ID=#{id}")
    void delete(@Param("id")int id);

    /**
     * 修改(先找到并显示，再修改)
     */
    @Select("select a.title as title,b.name as username,c.* from tourist_route a," +
            "userinfo b,my_hotel c where a.uid=b.openid and c.tid=a.id and c.id=#{id}")
    List<my_hotel> getUserone(@Param("id")int id);

    @Update("update my_hotel set tid=#{tid},name=#{name} where id=#{id}")
    void update(my_hotel my_hotel);

}
